
/**
 * 从微信 同步部门信息
 * 
 * 
 ***/


function syncDepart(_province){
 
	   $.ajax({ 
         type:"POST", 
         url:CONETXT_PATH+"/weixin/getDepart/"+_province,
              
     
         success:function(data){ 
         	//显示保存结果 
         	showTipInfo(data);         
         } 
      });
}



function createMenu(_province,_token){
	 
	   $.ajax({ 
      type:"POST", 
      url:CONETXT_PATH+"/weixin/createmenu/"+_province+"/"+_token,
           
  
      success:function(data){ 
      	//显示保存结果 
      	showTipInfo(data);         
      } 
   });
}



$(function() {
	// 设置 所有Item 的点击事件,ACTIVE 单选  ，select 多选
 

	$("body").on("click", ".item .name", function() {
		var _this = $(this).parent();
		_this.siblings().removeClass("active");
		_this.addClass("active");
		 return false;
	});
	
	/**
	 * 全局AJAX拦截
	 * */
	$(document).ajaxStart(onStart)
    .ajaxComplete(onComplete)
    .ajaxSuccess(onSuccess)
    .ajaxError(onError);

	function onStart(event) {
		//发送ajax  开启mask 
		 showMaskInfo();
	//.....
	}
	function onComplete(event, xhr, settings) {
		//发送ajax   wanc  关闭ajax  
		hideMaskInfo(false);
	//.....
	}
	function onSuccess(event, xhr, settings) {
	//.....
	}
	function onError(event, xhr, settings) {
		//.....
		if(xhr.status!=200) {
		      window.log("error  goto index  Dodem!!!!!!!!!!!!!!!!!!!!!",event,xhr,settings);
			//    location.href = CONETXT_PATH + "/"
		}
		//.....
		if(xhr.status=500) {
		       window.log("error  goto index  Dodem!!!!!!!!!!!!!!!!!!!!!",event,xhr,settings);
			  //  location.href = CONETXT_PATH + "/"
		}
   
	}
	
	
	$("body").on("click", ".logout>a", function() {

		$.getJSON(CONETXT_PATH + "/login/logout", function(data) {
			if (data.success == true) {
				location.href = CONETXT_PATH + "/"
			}
		});

	});
	
	

	 
	 
	 
	function adjustwindow(){
		/*var _width=$(window).width();
		var _height=$(window).height();
		_width=_width>1210?_width:1200;
		_height=_height>600?_height:600;
		$("body").css({width:_width,height:_height});*/
		
	  var d_width=$(".d_echarts").width();
		$(".d_echarts>div").width(d_width);
		$(".d_echarts>div>canvas").width(d_width);
	 
		 
	 
	}
	adjustwindow();
	window.onresize = function() {
		 

		adjustwindow();
	}

	// 自界面工具栏事件 根据根据需要
	$("body").on("click", ".page_view .close", function() {
		$(".page_view").removeClass('animated fadeInDownBig');
		$(".page_view").addClass('animated bounceOut');
		setTimeout(function() {
			$(".page_view").removeClass('animated bounceOut')
		}, 1000);

	});

	// 颜色切换
	function setColor(color) {

		$("html").css("background-color", color);

		$(".colorable").css("background-color", RGB2RGBA(color, 0.8));
	}
	var cor = $(".h_c_item:first").css("background-color");
	setColor(cor);

	$(".h_c_item").on("click", function() {
		var color = $(this).css("background-color");
		setColor(color);
	});

	$("#more_color").bigColorpicker(function(el, color) {
		setColor(color);
		// $("html").css("background",color);
	});

	$(".header .h_tool .h_t_item").on("mouseover", function() {
		var _tar = $(this).find("div");
		_tar.addClass("animated pulse");
		setTimeout(function() {
			_tar.removeClass('animated pulse')
		}, 1000);

	});
	$(".header .h_tool .h_t_item").on("mousedown", function() {
		var _tar = $(this);
		_tar.addClass("clicked");

	}).on("mouseup", function() {
		var _tar = $(this);
		_tar.removeClass("clicked");

	});

 
  //tab page 
	 $("body").on("click",".tabPageTitle .item",function(){
		  $(this).siblings().removeClass("active");
		  $(this).addClass("active");
	  });
	
 

});


//====================================================
function toolEvent(tar) {

	// if (tar.attr("id").indexOf("weixin_admin") > -1) {
	// location.href = tar.attr("href");
	// }
}

function checkJSHTML(ajaxLoadedData) {

	var regDetectJs = /<script(.|\n)*?>(.|\n|\r\n)*?<\/script>/ig;
	var jsContained = ajaxLoadedData.match(regDetectJs);

	// 第二步：如果包含js，则一段一段的取出js再加载执行
	if (jsContained) {
		// 分段取出js正则
		var regGetJS = /<script(.|\n)*?>((.|\n|\r\n)*)?<\/script>/im;

		// 按顺序分段执行js
		var jsNums = jsContained.length;
		for (var i = 0; i < jsNums; i++) {
			var jsSection = jsContained[i].match(regGetJS);

			if (jsSection[2]) {
				if (window.execScript) {
					// 给IE的特殊待遇
					window.execScript(jsSection[2]);
				} else {
					// 给其他大部分浏览器用的
					window.eval(jsSection[2]);
				}
			}
		}
	}
}
